package com.pvdnc.dxhook;

import android.util.SparseArray;

import java.lang.reflect.Method;
import java.util.Objects;

public class CalleeInfo {
    public CalleeInfo(Object oldObject,Method method){
        this(HookMode.OVERRIDE,method);
        mOldObjHashCode=oldObject.hashCode();
    }

    public CalleeInfo(HookMode hookMode,Method method){
        mHookMode=hookMode;

        mClassName=method.getDeclaringClass().getName();
        mMethodName=method.getName();
    }

    public enum HookMode{
        REPLACE,OVERRIDE
    }

    private HookMode mHookMode;

    public HookMode getHookMode(){
        return mHookMode;
    }

    private String mClassName;

    public String getClassName(){
        return mClassName;
    }

    private String mMethodName;

    public String getMethodName(){
        return mMethodName;
    }

    private int mOldObjHashCode;

    public int getOldObjectHashCode(){
        return mOldObjHashCode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CalleeInfo that = (CalleeInfo) o;
        return mOldObjHashCode == that.mOldObjHashCode &&
                mHookMode == that.mHookMode &&
                Objects.equals(mClassName, that.mClassName) &&
                Objects.equals(mMethodName, that.mMethodName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mHookMode, mClassName, mMethodName, mOldObjHashCode);
    }

    public String toJson(){
        return GsonUtils.toJson(this);
    }
}
